// Copyright (C) 2016  Francisco Javier Parra <franparpe@openmailbox.org>

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA


#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H

#include<gtkmm.h>
#include<iostream>
#include "conversation_container.h"
#include <string.h>
#include <gloox/message.h>
#include <gloox/messagehandler.h>
#include <gloox/connectionlistener.h>
#include <gloox/client.h>
#include "xmpplar_client.h"
#include <thread>
#include "widget_side_bar.hpp"

class XmpplarClient;

class MainWindow : public Gtk::ApplicationWindow
{
private:
  // here comes the widgets and variables
  Gtk::Button m_button, m_button2;
  ConversationContainer m_conversationCont;
  Gtk::Entry m_entry;
  widget::SideBar m_sidebar;
  Gtk::Button m_rosterpanel_reveal_btn;
  Gtk::Button m_test_hide_btn; // Remove later

  //For thread-GUI comunication
  Glib::Dispatcher m_msg_dispatcher;

  // Here comes containers
  Gtk::Overlay m_overlay;
  // Gtk::Box m_main_hbox;
  Gtk::Box m_hbox;
  Gtk::Box m_vbox;
  Glib::ustring m_text_msg;
  std::string m_text_msg_trd;
  Gtk::HeaderBar m_headerbar;

  // Here comes the xmppplar client
  XmpplarClient *m_xmpplar_client;

  // Here comes the connection thread
  std::thread *m_conn_thread;

public:
  MainWindow();
  // virtual ~MainWindow();
  void generateUI();
  void showHideSideBar();

  void sendMessage();
  void onConnectSignal();

  // React to notifications from the worker thread
  void message_notification();

  // React when a message have been received
  void on_message_from_gloox();

  void receiveMessage(const gloox::Message& stanza);
};


#endif
